using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using Utility;

namespace BUS
{
    public class tbDatHangBUS
    {
        public static tbDatHangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            return dhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDatHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            return dhDAL.Get(cri.Criter, 0, 0, tbDatHangColumns.stt.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbDatHang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDatHangColumns.stt.ToString(), Condition.EQUAL, iD);
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            tbDatHangCollection dhCollection = dhDAL.Get(cri.Criter, 0, 0, tbDatHangColumns.stt.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return dhCollection[0];
            return null;
        }

        public static int CountByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDatHangColumns.deals.ToString(), Condition.EQUAL, iD);
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            tbDatHangCollection dhCollection = dhDAL.Get(cri.Criter, 0, 0, tbDatHangColumns.deals.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return total;
            return 0;
        }

        public static void Insert(tbDatHang dh)
        {
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            dhDAL.Insert(dh);
        }
        public static void Update(tbDatHang dh)
        {
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            dhDAL.Update(dh);
        }
        public static void Delete(int id)
        {
            tbDatHangDAL dhDAL = new tbDatHangDAL();
            dhDAL.Delete(id);
        }
    }
}
